<template>
    <div>
        <div class="detail_body">
            <div class="title-info">
                <h2 class="detail-title" :title="noticeListDetail.article_title">{{ noticeListDetail.article_title }}</h2>
                <p class="detail-info">
                    <span>{{ noticeListDetail.created_at }}</span>
                </p>
                <button class="start-game" @click="open_game(noticeListDetail.game_id,noticeListDetail.pixel_code)">{{ $t('play_game') }}</button>
            </div>
            <div class="news-detail-con" >
                <div v-html="noticeListDetail.article_content"></div>
            </div>
        </div>
    </div>
</template>

<script setup>
import axios from '@/utils/api'
import { reactive } from "vue";
import { useRouter,useRoute } from 'vue-router'
import {useGetGameUrl} from '@/hooks/getGameUrl'
import { useUserInfoStore } from '@/store/modules/user_info/index';
const user_infoStore = useUserInfoStore();
let user_info = reactive(user_infoStore.userInfo)

const router = useRouter()
const route = useRoute();
const announcement_id = route.params.id;

const noticeListDetail = reactive([])
const getNoticeDetail = async () =>{
    const list = await axios.get('/getNoticeDetail?id='+announcement_id)
    Object.assign(noticeListDetail,list.data)
    console.log(noticeListDetail);
}
getNoticeDetail()

const open_game = async (game_id,pixel_code) => {
    const data = await useGetGameUrl(game_id,user_info.id)
    console.log(data,'data');
    if(data.code == 5002 || data.code == 5003 || data.message == 'Token失效'){
        // router.push('/login')
        return
    }

    // localStorage.setItem('game_url',data.game_url)
    const url = router.resolve({ path: '/playgame',query: { id: game_id,game_name: data.game_name,pixel_code } }).href;
    window.open(url);
    
}
</script>
<style>
	.news-detail-con p{
		position: relative;
		text-indent: 0;
	}
	.news-detail-con img{
		width: 100%;
	}
</style>
<style lang="less" scoped>
.detail_body {
    width: 80%;
    .news-detail-con {
        line-height: 24px;
        padding: 30px 50px;
        img{
			margin: 10px 0;
			width: 100%;
		}
    }
    .title-info {
        padding-top: 30px;
        border-bottom: 1px solid #E9E9E8;
        padding-bottom: 15px;
        height: 85px;
        position: relative;
        .start-game{
            font-size: 14px;
            width: 150px;
            height: 65px;
            background-color: #00aeec;
            color: #fff;
            border: transparent;
            display: inline-block;
            cursor: pointer;
            text-align: center;
            border-radius: 6px;
            margin-top: -5px;
            position: absolute;
            top: 46px;
            left: 50px;
        }
        .start-game:hover{
            background-color: rgba(#00aeec,.7);
        }
    }

    .detail-title {
        text-align: center;
        color: #b22e13;
        font-size: 20px;
        max-height: 57px;
        width: 450px;
        line-height: 27px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        margin-top: 10px;
    }

    .detail-info {
        text-align: center;
        color: #8c8c8c;
        margin-top: 10px;
    }
}
</style>